<template>
    <div ref="chartDom" class="SalesChart" style=" font-family: 'swis'"></div>
</template>

<script setup>
import * as echarts from "echarts";
import { ref } from "vue";
const chartDom = ref()
let myChart
const init = (purchaseList1, salesList1) => {
    let option = {
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ['purchase', 'sales']
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: ['Mon', "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
                name: 'purchase',
                type: 'line',
                stack: 'Total',
                data: purchaseList1
            },
            {
                name: 'sales',
                type: 'line',
                data: salesList1
            },
        ]
    };

    if (myChart != null && myChart != "" && myChart != undefined) {

        myChart.dispose();
    }

    myChart = echarts.init(chartDom.value, 'westeros')
    option && myChart.setOption(option);
    // 自动缩放
    window.addEventListener("resize", () => { myChart.resize() })
}

defineExpose({
    init,
    chartDom
})

</script>

<style lang="less">
.SalesChart {
    width: 100%;
    height: 43vh;
    padding: 10px;
    border: 1px solid #ffffff;
    background-color: #ffffff;
    border-radius: 10px;
    margin-top: 2vh;
}
</style>